<%--管理员-博客添加--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <title>图形图像处理交流网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/public.css" media="all">

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">
            <form:form id="fm" class="layui-form" action="" enctype="multipart/form-data" method="post">
                <div class="layui-form-item">
                    <label for="filename" class="layui-form-label">文件标题</label>
                    <div class="layui-input-inline">
                        <input type="text" id="filename" name="fName" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="fState" class="layui-form-label">文件说明</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="fState" name="fState" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="uploadFile" class="layui-form-label">选择文件</label>
                    <div class="layui-input-inline">
                        <input id="uploadFile" type="file" name="uploadFile"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn"  lay-filter="addForm" lay-submit>立即上传</button>
                </div>
            </form:form>
        </div>
    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js" ></script>
<script src="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

<%--提交表单--%>
<script>
    layui.use(['layer','form'],function(){
        var form=layui.form;
        var layer=layui.layer;
        form.on('submit(addForm)', function(data){
            var saveLoading = parent.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            var formData = new FormData($( "#fm" )[0]);
            $.ajax({
                url:'${pageContext.request.contextPath}/admin/file/add.do',
                method:'post',
                async: false,
                data : formData,
                cache:false,
                contentType: false,
                processData: false,
                success:function(res){
                    parent.layer.close(saveLoading);
                    switch(res.code){
                        case 200:
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg(res.msg, {icon: 1});
                            parent.layui.table.reload('test');//重载父页表格，参数为表格ID
                            parent.layer.close(index);
                            break;
                        case -1:
                            parent.layer.msg(res.msg, {icon: 2});
                            break;
                        case -2:
                            //登录失效
                            alert('登录失效');
                            window.open("${pageContext.request.contextPath}/user/to_login.do");
                            break;
                    }
                },
                error:function (data) {

                }
            }) ;

        });
    });
</script>

</body>
</html>
